package com.wilmer.knowledges.service.impl;

import com.wilmer.common.annotation.DataScope;
import com.wilmer.common.utils.DateUtils;
import com.wilmer.common.utils.SecurityUtils;
import com.wilmer.knowledges.domain.YwHomeKnowledge;
import com.wilmer.knowledges.mapper.YwHomeKnowledgeMapper;
import com.wilmer.knowledges.service.IYwHomeKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 育儿知识库Service业务层处理
 *
 * @author hans
 * @date 2024-04-18
 */
@Service
public class YwHomeKnowledgeServiceImpl implements IYwHomeKnowledgeService
{
    @Autowired
    private YwHomeKnowledgeMapper ywHomeKnowledgeMapper;

    /**
     * 查询育儿知识库
     *
     * @param knowledgeId 育儿知识库主键
     * @return 育儿知识库
     */
    @Override
    public YwHomeKnowledge selectYwHomeKnowledgeByKnowledgeId(Long knowledgeId)
    {
        return ywHomeKnowledgeMapper.selectYwHomeKnowledgeByKnowledgeId(knowledgeId);
    }

    /**
     * 查询育儿知识库列表
     *
     * @param ywHomeKnowledge 育儿知识库
     * @return 育儿知识库
     */
    @DataScope(deptAlias = "d")
    @Override
    public List<YwHomeKnowledge> selectYwHomeKnowledgeList(YwHomeKnowledge ywHomeKnowledge)
    {
        return ywHomeKnowledgeMapper.selectYwHomeKnowledgeList(ywHomeKnowledge);
    }

    /**
     * 新增育儿知识库
     *
     * @param ywHomeKnowledge 育儿知识库
     * @return 结果
     */
    @Override
    public int insertYwHomeKnowledge(YwHomeKnowledge ywHomeKnowledge)
    {
        ywHomeKnowledge.setCreateBy(SecurityUtils.getUsername());
        ywHomeKnowledge.setDeptId(SecurityUtils.getDeptId());
        ywHomeKnowledge.setCreateTime(DateUtils.getNowDate());
        return ywHomeKnowledgeMapper.insertYwHomeKnowledge(ywHomeKnowledge);
    }

    /**
     * 修改育儿知识库
     *
     * @param ywHomeKnowledge 育儿知识库
     * @return 结果
     */
    @Override
    public int updateYwHomeKnowledge(YwHomeKnowledge ywHomeKnowledge)
    {
        ywHomeKnowledge.setUpdateTime(DateUtils.getNowDate());
        return ywHomeKnowledgeMapper.updateYwHomeKnowledge(ywHomeKnowledge);
    }

    /**
     * 批量删除育儿知识库
     *
     * @param knowledgeIds 需要删除的育儿知识库主键
     * @return 结果
     */
    @Override
    public int deleteYwHomeKnowledgeByKnowledgeIds(Long[] knowledgeIds)
    {
        return ywHomeKnowledgeMapper.deleteYwHomeKnowledgeByKnowledgeIds(knowledgeIds);
    }
    /**
     * 删除育儿知识库信息
     *
     * @param knowledgeId 育儿知识库主键
     * @return 结果
     */
    @Override
    public int deleteYwHomeKnowledgeByKnowledgeId(Long knowledgeId)
    {
        return ywHomeKnowledgeMapper.deleteYwHomeKnowledgeByKnowledgeId(knowledgeId);
    }
    /**
     * 查询育儿知识库的文章数量
     * @return
     */
    @Override
    public int YwHomeKnowledgeCount() {
        return ywHomeKnowledgeMapper.YwHomeKnowledgeCount();
    }


}
